package com.utils;

import java.util.ArrayList;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.TourGuide.R;
import com.object.Instruction;

public class ListInstructionAdapter extends ArrayAdapter<Instruction> {

	private ArrayList<Instruction> instructions;
	private Context context;

	public ListInstructionAdapter(Context context, int textViewResourceId, ArrayList<Instruction> instructions) {
		super(context, textViewResourceId, instructions);
		this.context = context;
		this.instructions = instructions;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View v = convertView;
		if (v == null) {
			LayoutInflater vi = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			v = vi.inflate(R.layout.rowinstruction, null);
		}
		String name = instructions.get(position).getName();
		String description = instructions.get(position).getDescription();
		Log.v("adapter", name + " " + description);
		if (name != null) {
			TextView in = (TextView) v.findViewById(R.id.instructionName);
			TextView id = (TextView) v.findViewById(R.id.instructionDescription);
			if (in != null)
				in.setText(name);
			if(id != null)
				id.setText(description);
		}
		return v;
	}
}
